home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2006 September
/
PCWorld_2006-09_cd.bin
/
v cisle
/
samurize
/
samurize_1.64.exe
/
Packages
/
new dego 5.01.sam
/
scripts
/
ExternalIP.vbs
< prev
Wrap
Text File
|
2004-03-22
|
3KB
|
122 lines
'--------------------------------------------------------------------------------
' ExternalIP.vbs (v1.4)
'--------------------------------------------------------------------------------
'
' Retreives your external IP address from http://checkip.dyndns.org/ (this is
' useful for computers behind routers and firewalls)
'
' Changes in v1.4
'
' - internet connection detected (thanks AdamC)
'
'
' Changes in v1.3
'
' - international version returns 2 IP addresses if you have multiple NICs in your
' computer - fixed to only show one. (Thanks Rasman)
'
' Changes in v1.2
'
' - uses new URL to save bandwidth
' - Old script was actually returning proxy IP, not actual IP!
'
' Changes in v1.1:
'
' - Added error messages
' - Hid relevant functions from Samurize 0.85b
'
' -NeM
'--------------------------------------------------------------------------------
Const CheckConnected = True ' Whether you want the script to check if its connected to the internet
' Either True of False
Function getExternalIP ()
dim htmlResult
'Check that Computer is connected to the internet
Connected = IsConnectible("checkip.dyndns.org","","")
if Connected = True OR CheckConnected = False then
htmlResult = ReturnHTML("http://checkip.dyndns.org/")
leftMark = instr(htmlResult, "Address: " ) + 9
if Instr(htmlResult, ",") > 0 Then
rightMark = instr( htmlResult, ",") - 1
else
rightMark = instr( htmlResult, "</body>") - 1
End If
if rightMark > 0 Then
'grabs the IP
getExternalIP = mid( htmlResult, leftMark, rightMark - leftMark + 1)
else
getExternalIP = "ERROR"
end if
Else
getExternalIP = "Offline"
End If
End Function
Private Function ReturnHTML(sURL)
Dim objXMLHTTP,HTML
Set objXMLHTTP = CreateObject("Microsoft.XMLHTTP")
objXMLHTTP.Open "GET", sURL, False
objXMLHTTP.Send
HTML = objXMLHTTP.responseBody
Set objRS = CreateObject("ADODB.Recordset")
objRS.Fields.Append "txt", 200, 45000, &H00000080
objRS.Open
objRS.AddNew
objRS.Fields("txt").AppendChunk HTML
ReturnHTML = objRS("txt").Value
objRS.Close
Set objRS = Nothing
Set objXMLHTTP = Nothing
End Function
' This was done by someone on the forums which I copied, and can I find that post again can I heck
' So who every you are thanks for the cold.
Private Function IsConnectible(sHost,iPings,iTO)
' Works an "all" WSH versions
' sHost is a hostname or IP
' iPings is number of ping attempts
' iTO is timeout in milliseconds
' if values are set to "", then defaults below used
If iPings = "" Then iPings = 2
If iTO = "" Then iTO = 750
Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sTemp = oShell.ExpandEnvironmentStrings("%TEMP%")
sTempFile = sTemp & "\runresult.tmp"
oShell.Run "%comspec% /c ping -n " & iPings & " -w " & iTO & " " & sHost & ">" & sTempFile, 0 , True
Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, FailIfNotExist, OpenAsDefault)
sResults = fFile.ReadAll
fFile.Close
oFSO.DeleteFile(sTempFile)
Select Case InStr(sResults,"TTL=")
Case 0 IsConnectible = False
Case Else IsConnectible = True
End Select
End Function